package com.meihuak.cloud_ordering.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.meihuak.cloud_ordering.bean.Dish;
import com.meihuak.cloud_ordering.mapper.DishMapper;
import com.meihuak.cloud_ordering.service.DishService;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class DishServiceImpl extends ServiceImpl<DishMapper, Dish> implements DishService {


    /**
     * 通过商家id获取菜品
     *
     * @param id 商家id
     * @return 菜品列表
     */
    @Override
    public List<Dish> getDishByBusinessId(int id) {
        Map<String,Object> map = new HashMap<>();
        map.put("win_id",id);
        return this.listByMap(map);
    }

    /**
     * 更改菜品信息
     *
     * @param dish 菜品
     * @return 是否成功
     */
    @Override
    public boolean updateById(Dish dish) {
        return this.update(dish,new UpdateWrapper<Dish>());
    }

    /**
     * 增加菜品信息
     *
     * @param dish 菜品
     */
    @Override
    public void addDish(Dish dish) {
        this.save(dish);
    }

    /**
     * 获取菜品完成时间
     */
    @Override
    public int getDishFinishTimeById(int id) {
        return this.getById(id).getFinishtime();
    }
}
